package org.aplombh.java.study.test;

import java.util.*;

public class Main {
    public static void main(String[] agrs) {
        Scanner sc = new Scanner(System.in);
        int start = sc.nextInt();
        int end = sc.nextInt();
        int n = sc.nextInt();
        Range[] range = new Range[n];
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            range[i] = new Range(a, b);
        }
        Arrays.sort(range, (a, b) -> a.l - b.l);
        int res = 0;
        boolean flag = false;
        for (int i = 0; i < n; i++) {
            int j = i;
            int max_r = Integer.MIN_VALUE;
            while (j < n && range[j].l <= start) { //双指针一定要先满足 •••j < n•••
                max_r = Math.max(max_r, range[j].r);
                j++;
            }
            if (max_r < start) {
                //两种情况 ： 1.     -------
                //           ---- -- (压根进不来。。)
                //      2. ---------
                //        ---- ---- (由于range[i].l < start 不成立,所以max_r得不到更新，因此依旧小于)
                break;
            }

            //开始更新

            res++; //更新完再看结果
            if (max_r >= end) {
                flag = true;
                break;
            }
            start = max_r;
            i = j - 1; //切记要更新。。。 而且因为i会自动+1所以j要往前退一位
        }

        if (flag) {
            System.out.println(res);
        } else {
            System.out.println("-1");
        }

    }
}
class Range {
    int l;
    int r;
    public Range(int l, int r) {
        this.l = l;
        this.r = r;
    }
}